package com.open.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.open.common.utils.HttpContextUtils;
import com.open.common.utils.IPUtils;
import com.open.common.utils.IpInfo;
import com.open.system.dao.LoanAdminLogDao;
import com.open.system.dao.LoanShopDao;
import com.open.system.domain.LoanAdminLogDO;
import com.open.system.domain.LoanShopDO;
import com.open.system.service.LoanAdminLogService;



@Service
public class LoanAdminLogServiceImpl implements LoanAdminLogService {
	@Autowired
	private LoanAdminLogDao loanAdminLogDao;
	
	@Autowired
	private LoanShopDao loanShopDao;
	
	@Override
	public LoanAdminLogDO get(Long id){
		return loanAdminLogDao.get(id);
	}
	
	@Override
	public List<LoanAdminLogDO> list(Map<String, Object> map){
		return loanAdminLogDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return loanAdminLogDao.count(map);
	}
	
	@Override
	public int save(LoanAdminLogDO loanAdminLog){
		return loanAdminLogDao.save(loanAdminLog);
	}
	
	@Override
	public int update(LoanAdminLogDO loanAdminLog){
		return loanAdminLogDao.update(loanAdminLog);
	}
	
	@Override
	public int remove(Long id){
		return loanAdminLogDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return loanAdminLogDao.batchRemove(ids);
	}

	@Override
	public void saveLog(String shopId,String adminName,String Module,String detail){
		LoanShopDO shop=loanShopDao.get(Long.parseLong(shopId));
		LoanAdminLogDO adminLog=new LoanAdminLogDO();
		adminLog.setCreateTime(new Date());
		adminLog.setCity(IpInfo.getIpInfo(IPUtils.getIpAddr(HttpContextUtils.getHttpServletRequest())));
		adminLog.setIp(IPUtils.getIpAddr(HttpContextUtils.getHttpServletRequest()));
		if("1".equals(Module)){
			adminLog.setStatus("1");
		}else {
			adminLog.setStatus("2");
		}
		adminLog.setAdminName(adminName);
		adminLog.setRemark1(Module);//模块
		adminLog.setRemark2(detail);//细节
		adminLog.setRemark3(shop.getShopName());//店铺
		adminLog.setRemark4(String.valueOf(shop.getId()));
		loanAdminLogDao.save(adminLog);
	}
	
}
